
$(document).ready(function() {
	$("#bindwechat").click(function() {
		$("#popup-verifywechat").dialog({
			title: "绑定微信号",
			width: 620
		})
	});
	$("#editwechat").click(function() {
		$("#popup-verifyeditwechat").dialog({
			title: "修改微信号",
			width: 620
		})
	})
});

function checkUserWechat() {
	var a = $.trim($("#txtWechat").val());
	if (a == "") {
		dialog.error("消息", "用户微信号不能为空！");
		return false
	}
	$("#btnCheckWechat").attr("disabled", "disabled");
	$.post('checkWechat', {
		
		userwechat: a
	}, function(b) {
		if (b.success) {
			bindWechat()
		} else {
			dialog.error("消息",b.message);
			$("#btnCheckWechat").removeAttr("disabled")
		}
	},'json')
}
function bindWechat() {
	$.post('bindWechat', {
		type: 0,
		userwechat: $.trim($("#txtWechat").val())
	}, function(a) {
		if (a.success) {

				dialog.alert("消息",a.message,null,'/index.php/UserCenter/index');


		} else {
			dialog.error("消息",a.message)
		}
	},'json')
};
function checkEditWechat() {
	var a = $.trim($("#txtWechat2").val());
	if (a == "") {
		dialog.error("消息", "用户微信号不能为空！");
		return false
	}
	$("#btnCheckWechat").attr("disabled", "disabled");
	$.post('checkWechat', {
		type: 1,
		userwechat: a
	}, function(b) {
		if (b.success) {
			editWechat()
		} else {
			dialog.error("消息",b.message);
			$("#btnCheckWechat").removeAttr("disabled")
		}
	},'json')
}

function editWechat() {
	$.post('editWechat', {
		type: 0,
		userwechat: $.trim($("#txtWechat2").val())
	}, function(a) {
		if (a.success) {

				dialog.alert("消息",a.message,null,'/index.php/UserCenter/index');
				
		} else {
			dialog.error("消息",a.message)
		}
	},'json')
};







